# 方法一
class Solution:
    def uniqueOccurrences(self, arr: List[int]) -> bool:
        dict1 = defaultdict(int)
        for x in arr:
            dict1[x] += 1

        space = []
        for item in dict1:
            if dict1[item] in space:
                return False
            else:
                space.append(dict1[item])
        return True

# 方法二 排序+ 哈希
class Solution:
    def uniqueOccurrences(self, arr: List[int]) -> bool:
        arr.sort()
        n = len(arr)
        dic = {}
        signal = 1
        for i in range(1, n):
            if arr[i] != arr[i - 1]:
                if signal in dic:
                    return False
                dic[signal] = arr[i - 1]
                signal = 1
            else:
                signal += 1
        if signal in dic:
            return False
        return True
# 哈希+集合
class Solution:
    def uniqueOccurrences(self, arr: List[int]) -> bool:
        counts = Counter(arr)     # 统计每个元素出现次数
        counts_set = set()        # 所有的次数集合
        
        for cnt in counts.values():
            if cnt in counts_set: return False # 当前次数已出现，不是唯一的
            counts_set.add(cnt)
        
        return True